package org.bot.plugin.web.event;

import com.alibaba.fastjson.JSONObject;
import org.bot.api.event.DataStorage;
import org.bot.api.event.EventName;
import org.bot.api.event.Events;
import org.bot.api.flow.FlowNode;
import org.bot.plugin.web.util.SelectorType;
import org.bot.plugin.web.util.WebApi;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author 沧月
 * @create 0028 2023/9/28 11:29
 * @description <获取元素属性值>
 */

@Component
@EventName("获取属性")
public class WebGetAttribute implements Events {

    @Autowired
    WebApi webApi;

    @Override
    public Object exec(FlowNode node, DataStorage data) {
        String arg = node.getArg();
        JSONObject param = JSONObject.parseObject(arg);
        return webApi.getAttribute(webApi.getWebDriver(node), SelectorType.getType(node.getSelectorType()),
                param.getString("arg"), param.getString("key"));
    }
}
